<?php
/**
 * @version		$Id: view.html.php 8 2011-12-23 15:25:34Z netix.mail@gmail.com $
 * @package		ALM Hoster
 * @desription	Web hosting and domain menager for resellers
 * @subpackage	Components
 * @copyright	Copyright (C) 2011 ALM Studio. All rights reserved.
 * @author		ALM Studio
 * @email		info@alm-studio.net
 * @link		http://alm-studio.net
 * @license		Commercial
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');


class AlmHosterViewProduct extends JView
{
	
	protected $form = null;

	public function display($tpl = null) 
	{
		$form = $this->get('Form');
		$item = $this->get('Item');

		if (count($errors = $this->get('Errors'))) 
		{
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}
		$this->form = $form;
		$this->item = $item;
		$this->addToolBar();
		
		parent::display($tpl);
		$this->setDocument();
	}

	protected function addToolBar() 
	{
		JRequest::setVar('hidemainmenu', true);
		$isNew = ($this->item->ProductId == 0);
		JToolBarHelper::title($isNew ? JText::_('COM_ALMHOSTER_NEW_PRODUCT') : JText::_('COM_ALMHOSTER_EDIT_PRODUCT'), 'products');
		JToolBarHelper::apply('product.apply', 'COM_ALMHOSTER_APPLY');
		JToolBarHelper::save('product.save', 'COM_ALMHOSTER_SAVE_AND_CLOSE');
		JToolBarHelper::custom('product.save2new', 'save-new.png', 'save-new_f2.png', 'COM_ALMHOSTER_SAVE_AND_NEW', false);
		JToolBarHelper::cancel('product.cancel', $isNew ? 'COM_ALMHOSTER_CANCEL' : 'COM_ALMHOSTER_CLOSE');
	}

	protected function setDocument() 
	{
		$isNew = ($this->item->ProductId < 1);
		$document = JFactory::getDocument();
		$document->setTitle($isNew ? JText::_('COM_ALMHOSTER_PRODUCT_NEW') : JText::_('COM_ALMHOSTER_PRODUCT_EDIT'));
	}
}